import { CellRenderer } from "../../../../../fl/controls/listClasses/CellRenderer";
import { ObjCreate } from "../../common/ObjCreate";
import { Language } from "../../../../../extend/language/Language";
import { LevelLimitDefin } from "../../../../common/defin/LevelLimitDefin";
import { GTextFormat } from "../../../../common/GTextFormat";
import { FontUtil } from "../../../../common/font/FontUtil";
import { ColorConfig } from "../../../resource/ColorConfig";
import { ResouceConst } from "../../../../component/gconst/ResouceConst";
import { RoleAvatar } from "../../avatar/RoleAvatar";
import { Alert } from "../../../../../com/mui/controls/Alert";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { BFOrderData } from "../cellData/BFOrderData";
import { GameDefConfig } from "../../../resource/GameDefConfig";
import { EBattlefieldStatus } from "../../../../../Message/Public/EBattlefieldStatus";
import { GButton } from "../../../../../com/mui/controls/GButton";
import { ScaleBitmap } from "../../../../../com/mui/display/ScaleBitmap";
import { SBattlefieldInfo } from "../../../../../Message/Public/SBattlefieldInfo";
type int = number;
//class BFStateCellRenderer
    
    export  class BFStateCellRenderer extends CellRenderer
    {
        constructor()
        {
            super();
            this.init();
            return;
        }

        /* internal  */init(): void
        {
            this.mouseChildren = true;
            this.initStyle();
            this.createChildren();
            this.addListeners();
            return;
        }

        /* internal  */initStyle(): void
        {
            this.setStyle("downSkin", new Object /* flash.display.Bitmap */());
            this.setStyle("overSkin", new Object /* flash.display.Bitmap */());
            this.setStyle("upSkin", new Object /* flash.display.Bitmap */());
            this.setStyle("selectedDownSkin", new Object /* flash.display.Bitmap */());
            this.setStyle("selectedOverSkin", new Object /* flash.display.Bitmap */());
            this.setStyle("selectedUpSkin", new Object /* flash.display.Bitmap */());
            return;
        }

        /* internal  */createChildren(): void
        {
            this._tfNeedLevel = ObjCreate.createTextField(Language.getStringByParam(41620, LevelLimitDefin.BattlefieldMinLevel.toString()), 20, 9, 90, 20, this);
            this._tfBattlefieldName = ObjCreate.createTextField("", 116, 9, 90, 20, this);
            this._btnState = ObjCreate.createGButton(this.TextComeIn, 230, 5, 56, 22, this);
            var loc1=new GTextFormat(FontUtil.songtiName, 12, ColorConfig.instance.getCampColor(1).intColor);
            this._tfCampNum1 = ObjCreate.createTextField("", 20, 33, 90, 20, this, loc1);
            var loc2=new GTextFormat(FontUtil.songtiName, 12, ColorConfig.instance.getCampColor(2).intColor);
            this._tfCampNum2 = ObjCreate.createTextField("", 116, 33, 90, 20, this, loc2);
            var loc3=new GTextFormat(FontUtil.songtiName, 12, ColorConfig.instance.getCampColor(3).intColor);
            this._tfCampNum3 = ObjCreate.createTextField("", 212, 33, 90, 20, this, loc3);
            this._bmpLine = ResouceConst.getScaleBitmap("SplitLine");
            this._bmpLine.x = 0;
            this._bmpLine.y = 58;
            this._bmpLine.width = 316;
            this._bmpLine.height = 2;
            this.addChild(this._bmpLine);
            this._btnState.drawNow();
            return;
        }

        /* internal  */addListeners(): void
        {
            this._btnState.addEventListener(flash.events.MouseEvent.CLICK, this.onComein);
            return;
        }

        /* internal  */onComein(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this.battlefieldInfo && this._btnState.label == this.TextComeIn) 
            {
                RoleAvatar.alertChangeMode(this.callBack);
            }
            return;
        }

        /* internal  */callBack(arg1: int): void
        {
            if (arg1 == Alert.OK) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.BattlefieldRequestComein, this.battlefieldInfo.id));
            }
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            super.data = arg1;
            if (typeof arg1 === "bforderdata") 
            {
                this.battlefieldInfo = (arg1 as BFOrderData).battlefieldInfo;
                this._tfBattlefieldName.text = Language.getStringByParam(41621, (arg1 as BFOrderData).rank.toString());
                this._tfCampNum1.text = GameDefConfig.instance.getECamp(1) + "（" + this.battlefieldInfo.num1 + "/" + this.battlefieldInfo.maxPlayer + "）";
                this._tfCampNum2.text = GameDefConfig.instance.getECamp(2) + "（" + this.battlefieldInfo.num2 + "/" + this.battlefieldInfo.maxPlayer + "）";
                this._tfCampNum3.text = GameDefConfig.instance.getECamp(3) + "（" + this.battlefieldInfo.num3 + "/" + this.battlefieldInfo.maxPlayer + "）";
                if (this.battlefieldInfo.status.value() != EBattlefieldStatus._EBattlefieldStatusClose) 
                {
                    this._btnState.label = this.TextComeIn;
                }
                else 
                {
                    this._btnState.label = this.TextNotOpen;
                }
            }
            return;
        }

        public /* override */ set label(arg1: string)
        {
            return;
        }

        /* internal */ /* const */TextComeIn: string=Language.getString(41618);

        /* internal */ /* const */TextNotOpen: string=Language.getString(41619);

        /* internal */ /* var */_tfNeedLevel: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfBattlefieldName: Object /* flash.text.TextField */;

        /* internal */ /* var */_btnState: GButton;

        /* internal */ /* var */_tfCampNum1: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfCampNum2: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfCampNum3: Object /* flash.text.TextField */;

        /* internal */ /* var */_bmpLine: ScaleBitmap;

        /* internal */ /* var */battlefieldInfo: SBattlefieldInfo;
    }
